/**
 * [71] 简化路径
 *
 * @format
 * @lc app=leetcode.cn id=71 lang=javascript
 */

// @lc code=start
/**
 * @param {string} path
 * @return {string}
 */
var simplifyPath = function (path) {
    const stack = []
    path = path.split(/\/+/)
    for (let dir of path) {
        if (dir == "." || dir == "") continue
        else if (dir == "..") stack.pop()
        else stack.push(dir)
    }
    return "/" + stack.join("/")
}
// debugger
// let path = "/a/../../b/../c//.//"
// console.log("简化前：", path)
// path = simplifyPath(path)
// console.log("简化后：", path)
// @lc code=end
